

const path = require('path');
const staticImg = path.join(__dirname, 'static');

function SensorbitUnoBlocks(Blockly) {
    var color_sensor = "#28BFE6";



    //普通超声波模块初始化
    Blockly.Blocks.microbit_ultrasonicInit = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/40.ph_ultrasonic.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_ULTRASONICPININIT)
        .appendField(Blockly.Msg.MICROBIT_TRIGPORT)
        .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P8', "pin8"],
            ['P12', "pin12"],
            ['P13', "pin13"],
            ['P15', "pin15"],
        ]),"trigPort")
        .appendField(Blockly.Msg.MICROBIT_ECHOPORT)
        .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P2', "pin2"],
            ['P12', "pin12"],
            ['P14', "pin14"],
            ['P16', "pin16"],
        ]),"echoPort")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    //普通超神波传感器读取距离
    Blockly.Blocks.microbit_ultrasonicDistance = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/40.ph_ultrasonic.svg", 84, 42))
                .appendField(Blockly.Msg.MICROBIT_ULTRASONICDISTANCE)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
        this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };

    return Blockly;
}

module.exports = SensorbitUnoBlocks;

